package graph;

/**
 * description:
 * author:张腾
 * date:2021-04-13
 */

import list.Stack;

/**
 * 拓扑排序
 * 先检测图中是否有有向环，如没有则进行顶点排序，如有则不排序
 */
public class TopoLogical {

    //顶点的拓扑排序
    private Stack<Integer> order;

    public TopoLogical(DiGraph G){
        DirectedCycle circle = new DirectedCycle(G);
        if (!circle.hasCycle()){
            DepthFirstOrder depthFirstOrder = new DepthFirstOrder(G);
            order = depthFirstOrder.reversePost();
        }
    }

    //判断G图中是否有环
    private boolean isCircle(){
        return order==null;
    }

    private Stack<Integer> order(){
        return order;
    }
}
